package top.greatxiaozou.singleton;

/**
 * 双重校验锁（DCL）实现单例模式
 */
public class DCLSingletonClass {
    //使用volatile放置指令重排
    private static volatile DCLSingletonClass instance;
    private DCLSingletonClass(){}

    public static DCLSingletonClass getInstance(){
        if (instance == null){
            synchronized (DCLSingletonClass.class){
                //双重校验锁
                if (instance == null){
                    instance = new DCLSingletonClass();
                }
                return instance;
            }
        }
        return instance;
    }
}
